<?php
namespace Api\Controller;
use Think\Controller;
class CommentController extends CommonController{

        public function lists() {

            //判断用户是否登录
            $token = I("post.token");

            $currentUser = $this->userModel->queryByToken($token);

            if(isNullOrEmpty($currentUser)) {
                $this->errorReturn("ERROR_TOKEN");
            }

            //判断师傅是否存在
            $masterId = I("post.masterId");

            $master = $this->userModel->queryById($masterId);

            if(isNullOrEmpty($master)) {
                $this->errorReturn("ERROR_MASTER_NOT_FOUND");
            }

            $pageNum = I('post.pageNum') ? I('post.pageNum') : C('DEFAULT_PAGE');

            $list = $this->commentModel->queryListByMasterId($masterId, $pageNum);

            $this->returnData['data']['list'] = $list;

            $this->response($this->returnData, 'json');

        }


        public function createComment() {


            //判断用户是否登录
            $token = I("post.token");

            $currentUser = $this->userModel->queryByToken($token);

            if(isNullOrEmpty($currentUser)) {
                $this->errorReturn("ERROR_TOKEN");
            }

            $errorCode = $this->commentModel->createComment($currentUser["user_id"]);

            $this->errorReturn($errorCode);

        }


}